fix(evm): skip JUMPDEST skip-cost metering when in dead code#365
Open
starwarfan wants to merge 1 commit intoDTVMStack:mainfrom
Open
fix(evm): skip JUMPDEST skip-cost metering when in dead code#365starwarfan wants to merge 1 commit intoDTVMStack:mainfrom
starwarfan wants to merge 1 commit intoDTVMStack:mainfrom
Conversation
When a consecutive JUMPDEST run follows dead code (e.g., after an unconditional JUMP), meterOpcodeRange was called while CurBB was already terminated. This appended gas-metering instructions (including a BrIfInstruction terminator) after the existing terminator, creating a basic block with two terminators. LLVM's MC assembler then emitted a branch to the ContinueBB label but never defined it (the block was unreachable), producing "Undefined temporary symbol .LBB0_43". Guard the meterOpcodeRange call with !InDeadCode. When execution reaches a JUMPDEST via an indirect jump, the per-target entry thunks already charge the correct skip cost, so the linear-path metering is unnecessary and incorrect in the dead-code case. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a consecutive JUMPDEST run follows dead code (e.g., after an unconditional JUMP),
meterOpcodeRangewas called whileCurBBwas already terminated. This appended gas-metering instructions (including aBrIfInstructionterminator) after the existing terminator, creating a basic block with two terminators. LLVM's MC assembler then emitted a branch to theContinueBBlabel but never defined it (the block was unreachable), producingUndefined temporary symbol .LBB0_43.Fix: Guard the
meterOpcodeRangecall with!InDeadCode. When execution reaches a JUMPDEST via an indirect jump, the per-target entry thunks already charge the correct skip cost, so the linear-path metering is unnecessary and incorrect in the dead-code case.1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
2. What is the scope of this PR (e.g. component or file name):
src/action/evm_bytecode_visitor.h
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
The bytecode visitor merges consecutive JUMPDEST opcodes into a single run and calls
meterOpcodeRangeto charge the skip cost for the JUMPDESTs that the linear decode skips over. However, when the JUMPDEST run is preceded by dead code (e.g., after a JUMP or STOP),CurBBis still the terminated block from the previous control-flow instruction.Calling
meterGasinsidemeterOpcodeRangeappends a gas-check branch (BrIfInstruction) plus a newContinueBBto the already-terminatedCurBB. This produces a basic block with two terminators. LLVM drops the unreachableContinueBBduring codegen but still emits a branch reference to its label, causing the MC assembler errorUndefined temporary symbol .LBB0_43.The fix is safe because indirect jumps landing on a merged JUMPDEST already go through per-target entry thunks (created in
createJumpTable) that charge the exact skip cost. The linear-pathmeterOpcodeRangeis only needed for fall-through, which cannot happen whenInDeadCodeis true.4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Provide a description of the tests:
Verified with
crash-bf1bdbf1(the crash file that triggeredUndefined temporary symbol .LBB0_43) using evmone-fuzzer in multipass mode. All 7 remaining crash files infuzz_output/pass after the fix. Code format check (./tools/format.sh format) passes.Made with Cursor